<?php

class CS_Error_Exception extends ErrorException
{
	public function printError()
	{
		// TODO : set template, automatically show error template
		$error 	= $this->getMessage()."\n";
		$error .= $this->getTraceAsString();

		if(headers_sent())
		{
			$error .= "\n\n<a href=\"".$_SERVER['PHP_SELF']."\">Refresh Page</a>";
			$file = md5($error).'.php';
			
			// redirecto to error page;
			$fp = fopen('tmp/error/'.$file, 'w+');
			fwrite($fp, nl2br($error));
			fclose($fp);

			echo '	<script type="text/javascript">
						document.location = "tmp/error/'.$file.'";
					</script>';
		} else {
			// show error page inline
			echo nl2br($error);
		}

		exit;
	}
}
